﻿using System.Collections.Generic;
using Newtonsoft.Json;

namespace T.FAS.Runtime.Metadata.Entity.MF
{
    public class LLMNode : NodeBase
    {
        [JsonProperty("data")]
        public new LLMNodeData Data { get; set; }
    }
    public class LLMNodeData
    {
        [JsonProperty("model")]
        public LLMModel Model { get; set; }
        [JsonProperty("temperature")]
        public double? Temperature { get; set; }
        [JsonProperty("maxTokens")]
        public int? MaxTokens { get; set; }

        [JsonProperty("topP")]
        public int? TopP { get; set; }
        [JsonProperty("frequencyPenalty")]
        public int? FrequencyPenalty { get; set; } = 0;
        [JsonProperty("prompt")]
        public Dictionary<string,string> OldPrompts { get; set; }
        [JsonProperty("prompt_template")]
        public List<PromptTemplateNode> Prompts { get; set; }
        //[JsonProperty("context")]
        //public ContextNode_back Context { get; set; }
        [JsonProperty("outputParser")]
        public string OutputParser { get; set; }
        [JsonProperty("jsonSchema")]
        public string JsonSchema { get; set; }
        [JsonProperty("variables")]
        public Dictionary<string, PromptVaribleNode> Variables { get; set; }
        [JsonProperty("timeout")]
        public string Timeout { get; set; }
        [JsonProperty("label")]
        public string Label { get; set; }
        [JsonProperty("description")]
        public string Description { get; set; }
        [JsonProperty("status")]
        public string Status { get; set; }
        [JsonProperty("retryConfig")]
        public RetryConfigNode RetryConfig { get; set; }

        [JsonProperty("outputFields")]
        public List<LLMOutputField> OutputVariables { get; set; }
    }
    public class LLMModel
    {
        [JsonProperty("provider")]
        public string Provider { get; set; }
        [JsonProperty("name")]
        public string Name { get; set; }
        [JsonProperty("mode")]
        public string Mode { get; set; }
        [JsonProperty("completion_params")]
        public Dictionary<string,object> CompletionParams { get; set; }
    }
    public class PromptTemplateNode
    {
        [JsonProperty("id")]
        public string ID { get; set; }
        [JsonProperty("role")]
        public string Role { get; set; }
        [JsonProperty("text")]
        public string Text { get; set; }
        [JsonProperty("tokens")]
        public List<PromptToken> Tokens { get; set; }

    }
    public class PromptToken
    {
        [JsonProperty("nodeId")]
        public string NodeID { get; set; }
        [JsonProperty("variableId")]
        public string VariableID { get; set; }
        [JsonProperty("variableCode")]
        public string VariableCode { get; set; }
    }
    public class RetryConfigNode
    {
        [JsonProperty("maxRetries")]
        public int MaxRetries { get; set; }
        [JsonProperty("retryDelay")]
        public int RetryDelay { get; set; }

    }
    public class PromptVaribleNode
    {
        [JsonProperty("nodeId")]
        public string NodeID { get; set; }
        [JsonProperty("dataType")]
        public string DataType { get; set; }

        [JsonProperty("variable")]
        public string VariableName { get; set; }
        [JsonProperty("variableId")]
        public string VariableID { get; set; }

    }
    public class LLMOutputField
    {
        [JsonProperty("type")]
        public string Type { get; set; }
        [JsonProperty("valueType")]
        public string ValueType { get; set; }

        [JsonProperty("variable")]
        public string VariableName { get; set; }
        [JsonProperty("variableId")]
        public string VariableID { get; set; }
        [JsonProperty("variableType")]
        public string VariableType { get; set; }
        [JsonProperty("variableValue")]
        public string VariableValue { get; set; }
    }
}
